package subject_set.weekly_competition.day10_23;

import java.util.*;

/**
 * @author haomin
 * @date 2022/10/23 10:23
 **/
public class Num2 {
    class Solution {
        int ans = 0;
        Set<List<Integer>> res = new HashSet<>();
        public int subarrayGCD(int[] nums, int k) {
            for(int i = 0; i < nums.length; ++i) nums[i] /= k;
            boolean[] flag = new boolean[nums.length];
            dfs(nums, flag, new ArrayList<>());
            for (List<Integer> re : res) {
                if(re.contains(1))ans++;
                System.out.println(re);
            }
            return ans;
        }

        private void dfs(int[] nums, boolean[] flag, List<Integer> ret) {
            Collections.sort(ret);
            res.add(new ArrayList<>(ret));
            for(int i = 0; i < nums.length; ++i){
                if(nums[i] == 0) continue;
                if(flag[i]) continue;
                ret.add(nums[i]); flag[i] = true;
                dfs(nums, flag, ret);
                ret.remove(ret.size()-1); flag[i] = false;
            }
        }
    }

}